package com.huajin.codetest.jol;

import java.util.concurrent.TimeUnit;

import org.openjdk.jol.info.ClassLayout;

public class SynchronizedTest {
	
	public static void main(String[] args) {
//		try {
//		    TimeUnit.SECONDS.sleep(5);
//		} catch (InterruptedException e) {
//		    e.printStackTrace();
//		}
		Object lock = new Object();
		System.out.println(ClassLayout.parseInstance(lock).toPrintable());
		synchronized (lock){
		    System.out.println(ClassLayout.parseInstance(lock).toPrintable());
		}
		System.out.println(ClassLayout.parseInstance(lock).toPrintable());
//		try {
//		    TimeUnit.SECONDS.sleep(5);
//		} catch (InterruptedException e) {
//		    e.printStackTrace();
//		}
//		System.out.println(ClassLayout.parseInstance(lock).toPrintable());
		new Thread(new Runnable() {
		    @Override
		    public void run() {
		        synchronized (lock) {
		            System.out.println("线程1-1");
		            System.out.println(ClassLayout.parseInstance(lock).toPrintable());
		            try {
		                TimeUnit.SECONDS.sleep(2);
		            } catch (InterruptedException e) {
		                e.printStackTrace();
		            }
		        }
		    }
		}).start();
		System.out.println(ClassLayout.parseInstance(lock).toPrintable());
	}

}
